import 'package:flutter/material.dart';

/// 颜色工具类
class ColorUtils {
  /// 验证16进制颜色值
  static bool validateHexColor(String color) {
    return RegExp(r'^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$').hasMatch(color);
  }

  /// 规范化16进制颜色值
  static String normalizeHexColor(String color) {
    if (color.startsWith('#')) {
      return color;
    }
    return '#$color';
  }

  /// 16进制颜色转Color对象
  static Color hexToColor(String hexColor) {
    hexColor = hexColor.toUpperCase().replaceAll('#', '');
    if (hexColor.length == 6) {
      hexColor = 'FF' + hexColor;
    }
    return Color(int.parse(hexColor, radix: 16));
  }

  /// Color对象转16进制颜色
  static String colorToHex(Color color) {
    return '#${color.value.toRadixString(16).substring(2).toUpperCase()}';
  }
}